#include<iostream>
using namespace std;
#include<vector>

class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int left = 0, right = 0;
        int n = nums.size();
        int i = 0, ret = INT_MIN;
        int sum = 0;
        for (i = 0; i < n; i++)
        {
            sum += nums[i];
        }
        if (sum < x)
        {
            return -1;
        }
        int target = sum - x;
        int sum1 = 0;
        while (right < n)
        {

            sum1 += nums[right++];

            while (sum1 > target)
            {
                sum1 -= nums[left];
                if (left < right)
                {
                    left++;
                }
            }
            if (sum1 == target)
            {
                ret = max(ret, right - left);
            }
            //right++;
        }
        if (ret == INT_MIN)
        {
            return -1;
        }


        return n - ret;

    }
};
int main()
{
    vector<int> a = { 1,1,4,2,3 };
    Solution s1;
    s1.minOperations(a,5);

    return 0;
}